#include <stdio.h>
#include <malloc.h>

// 定义链表节点结构
typedef struct Node {
    int data;               // 节点数据
    struct Node *next;      // 指向下一个节点的指针
} Node;

void printList(Node* head){
    if(head == NULL){
        return;
    }
    Node* temp = head;
    temp = temp->next;
    while (temp != NULL){
        printf("%d%s",temp->data,temp->next==NULL?"":" ");
        temp = temp->next;
    }
}
void input(Node*s){
    int a;
    Node *p,*l;
    l = s;
    while (scanf("%d", &a) && a >= 0) {
        p = (Node *)malloc(sizeof(Node));
        p->data = a;
        p->next = NULL;
        l->next = p;
        l = p;
    }
}
Node* sort(Node *s1,Node *s2){
    Node* result = (Node*) malloc(sizeof (Node));
    result->next = NULL;
    Node* tail = result;
    Node* p1 = s1->next;
    Node* p2 = s2->next;
    while (p1 && p2){
        if(p1->data<p2->data){
            tail->next = p1;
            p1 = p1->next;
        } else{
            tail->next = p2;
            p2 = p2->next;
        }
        tail = tail->next;
    }
    if(p1){
        tail->next = p1;
    } else {
        tail->next = p2;
    }
    return result;
}
int main() {
    Node *s1 = (Node *)malloc(sizeof (Node));
    Node *s2 = (Node *)malloc(sizeof (Node));
    s1->next = NULL;
    s2->next = NULL;
    input(s1);
    input(s2);
    Node *s3 = sort(s1, s2);
    if(s3->next==NULL){
        printf("NULL");
    } else{
        printList(s3);
    }
    free(s1);
    free(s2);
    free(s3);
    return 0; // 退出程序
}